package com.yw.swagger.service.serviceImpl;

import com.yw.swagger.mapper.WebMailMapper;
import com.yw.swagger.model.WebMail;
import com.yw.swagger.model.WebMailUpload;
import com.yw.swagger.service.WebMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 14267 on 2019/10/24
 */
@Service
public class WebMailServiceImpl implements WebMailService {

    @Autowired
    private WebMailMapper webMailMapper;

     //添加发送邮件
    @Override
    public int insertWebMail(WebMail webMail) {
        return webMailMapper.insertWebMail(webMail);
    }

     //保存附件
    @Override
    public int insertWebMailF(WebMail webMail, WebMailUpload upload) {
        //文件名字
        if(upload.getFilename().equals("null")){
            return 1;
        }
        String fileName[]=upload.getFilename().split(":::");
        System.err.println("文件名字:"+upload.getFilename());
        //文件路径
        String filePath[]=upload.getFilepath().split(":::");
        System.err.println("文件:"+upload.getFilepath());
        int j=0;
        for(int i=0;i<fileName.length;i++){
            upload.setID(webMail.getGuid());
            upload.setFilename(fileName[i]);
            upload.setFilepath(filePath[i]);
            //保存附件
           j=webMailMapper.insertWebMailF(upload);
        }
        return j;
    }

     //查询所有邮件
    @Override
    public List<WebMail> selectWebMailAll(String title) {
        return webMailMapper.selectWebMailAll(title);
    }

     //分页查询某发件人全部邮件
    @Override
    public List<WebMail> selectMailSendUserAll(WebMail webMail) {
        return webMailMapper.selectMailUserAll(webMail);
    }

     //分页查询某收件人全部邮件
    @Override
    public List<WebMail> selectMailtoAllSend(WebMail webMail) {
        return webMailMapper.selectMailSendUserAll(webMail);
    }

     //查询WebMail表详细信息
    @Override
    public WebMail selectWebMail(WebMail webMail) {
        //标记为邮件已读
        return webMailMapper.selectWebMail(webMail);
    }

     //查询WebMail附表表详细信息
    @Override
    public List<WebMailUpload> selectNoticeFileByNoticeId(String guid) {
        return webMailMapper.selectNoticeFileByNoticeId(guid);
    }

    //标记邮件为已读
    @Override
    public int updateMailRead(WebMail webMail) {
        //发件人改为已读
        webMailMapper.updateMailSendRead(webMail);
        return webMailMapper.updateMailRead(webMail);
    }

     //查看指定账号的全部未读邮件
    @Override
    public List<WebMail> selectMailUnread(WebMail mail) {
        return webMailMapper.selectMailUnread(mail);
    }
     //查看指定账号的全部已读邮件
    @Override
    public List<WebMail> selectMailRead(WebMail mail) {
        return webMailMapper.selectMailRead(mail);
    }
    //收件人删除多条邮件
    @Override
    public int deleteByIds(String uuid, String toSend) {
        String[] id=uuid.split(",");
        return webMailMapper.deleteByIds(id,toSend);
    }
    //发件人删除多条邮件
    @Override
    public int deleteFaByIds(String uuid, String SendUserAccount) {
        String[] id=uuid.split(",");
        for(int i=0;i<id.length;i++){
            System.err.println("删除id:"+id[i]);
        }
        return webMailMapper.deleteFaByIds(id,SendUserAccount);
    }


}
